from rest_framework import serializers
from . import models

class CourseCategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = models.CourseCategory
        fields = ['id','name']


class TeacherSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Teacher
        fields = ('name','role_name','title','signature','image','brief')


class CourseSerializer(serializers.ModelSerializer):
    #子序列化的方式
    teacher = TeacherSerializer(many=False)
    # course_type_name= serializers.CharField(source='course_type_name')  #可以不写，会自动映射过去，因为在models中写 了
    class Meta:
        model = models.Course
        fields = [
            'id',
            'name',
            'course_img',
            'brief',
            'attachment_path',
            'pub_sections',
            'price',
            'students',
            'period',
            'sections',
            'course_type_name',
            'level_name',
            'status_name',
            'teacher',
            'section_list',
        ]

#课时序列化类
class CourseSectionSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.CourseSection
        fields = '__all__'


#课程章节序列化类
class CourseChapterSerializer(serializers.ModelSerializer):
    #子序列化
    coursesections = CourseSectionSerializer(many=True)
    class Meta:
        model = models.CourseChapter
        fields = ['chapter','name','summary','pub_date','coursesections']


